package com.yc.yyds.servlet;

import com.yc.yyds.Bean.Result;
import com.yc.yyds.biz.BizException;
import com.yc.yyds.biz.DanmuBiz;
import com.yc.yyds.util.ToJsonUtil;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet(name = "DanmuQueryServlet", value = "/DanmuQueryServlet.s")
public class DanmuQueryServlet extends HttpServlet {
    DanmuBiz biz = new DanmuBiz();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String movieid = request.getParameter("movieid");
        Result result;
        try {
            List<Map<String, Object>> list = biz.query(movieid);
            long num = biz.num(movieid);
            Map<String,Object> data =new HashMap<>();
            data.put("num",num);
            data.put("data",list);
            result = new Result(1,"查询成功",data);
            ToJsonUtil.toJson(response,result);
        } catch (BizException e) {
            e.printStackTrace();
            result = new Result(0,e.getMessage(),null);
            ToJsonUtil.toJson(response,result);
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
